package com.response; /**
 * @author wzm
 * @create 2023-04-28 10:39
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/rs2")
public class ResponseServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置响应字符的编码
        //response.setCharacterEncoding("UTF-8");
        //设置响应内容的类型
        //response.setHeader("Content-Type","text/html");

        //同时设置编码和响应类型
        response.setContentType("text/html;charset=UTF-8");



        //向浏览器响应一个简单的字符串
        //1.通过response获取字符输出流
        PrintWriter writer = response.getWriter();
        //2.使用输出流中的write方法向浏览器写内容
        writer.write("<h1>HelloWorld！！你好，世界</h1>");


//        response.getWriter().write();

    }
}
